using System;
using System.Collections;

namespace PKGames.AssetLoader
{
	public abstract class AssetRequest
	{
		public enum State
		{
			Ready,
			Executing,
			Paused,
			Successful,
			Failed
		}

		public Action<AssetRequest> OnFinished;

		public Action OnFailure;

		protected string _localPath;

		private string Tag => "[AssetRequest] ";

		public State CurrentState
		{
			get;
			protected set;
		}

		public string Id => _localPath;

		public AssetRequest()
		{
			CurrentState = State.Ready;
		}

		public bool IsComplete()
		{
			return CurrentState == State.Successful || CurrentState == State.Failed;
		}

		public IEnumerator WaitForCompletion()
		{
			while (!IsComplete())
			{
				yield return null;
			}
		}

		public bool WasSuccessful()
		{
			return CurrentState == State.Successful;
		}

		public abstract IEnumerator Execute();

		public abstract void Pause();

		public abstract void Resume();

		public abstract void Cancel();
	}
}
